//
//  UIImageView+Kylin_UIImageView.m
//  03-BuDeJie-2 TabBar设置
//
//  Created by Kylin on 16/2/10.
//  Copyright © 2016年 kylin. All rights reserved.
//

#import "UIImageView+Kylin_UIImageView.h"
#import <UIImageView+WebCache.h>

@implementation UIImageView (Kylin_UIImageView)

- (void)setIconWithURL:(NSString *)url{
    
    [self setCircleIconWithURL:url];
}


// 调用方法返回一张矩形的图片
- (void)setRectIconWithURL:(NSString *)url{
    
    [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"defaultUserIcon"]];
}

- (void)setCircleIconWithURL:(NSString *)url{
    
    Kylin_WeakSelf
    
    // 把原来图片变成一第圆形图片
    UIImage *placeHolder = [[UIImage imageNamed:@"defaultUserIcon"]circleImage];
    
    [self sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:placeHolder completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
        if(image == nil)return ;
       
        
        //先让下载好的image对象调用一次circleImage变成一第圆形图片 再赋值给当前的imageView中的image
        weakSelf.image = [image circleImage];
    }];
    
}
@end
